Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Void fibo(int n) { if(n==0 || n==1) { return ... Start Learning for Free
Void fibo(int n) { if(n==0 || n==1) { return n; } return fibo(n-1)+fibo(n-2); } Is it linear recursion or tree recursion? Is head and tail recursion comes under linear recursion? Is this function an example of head recursion?
Most Upvoted Answer
Void fibo(int n) { if(n==0 || n==1) { return n; } return fibo(n-1)+fib...
Linear Recursion vs Tree Recursion

- Linear Recursion: In linear recursion, a function calls itself only once in each recursive call. The recursion progresses in a linear manner, where each recursive call leads to a single subsequent recursive call until the base case is reached. Examples of linear recursion include factorial and fibonacci functions.

- Tree Recursion: In tree recursion, a function calls itself multiple times in each recursive call. This leads to a branching structure, where each recursive call can further branch out into multiple recursive calls. Examples of tree recursion include functions that calculate the factorial of a number using multiple recursive calls.

Head Recursion

Head recursion is a type of linear recursion where the recursive call is made before any other operations in the function. In head recursion, the recursive call is the first line of code in the function, followed by other operations.

Analysis of the Given Function

The given function is an example of fibonacci recursion, which is a linear recursion. Let's analyze the function and check if it falls under head recursion.

```
void fibo(int n) {
if(n==0 || n==1) {
return n;
}
return fibo(n-1) + fibo(n-2);
}
```

1. Base Case: The function checks if the input `n` is equal to 0 or 1. If true, it directly returns the value of `n`. These are the base cases that terminate the recursion.

2. Recursive Calls: If the input `n` is not 0 or 1, the function makes two recursive calls - `fibo(n-1)` and `fibo(n-2)`. These calls are made before any other operations in the function, indicating that it falls under head recursion.

3. Return Statement: The function returns the sum of the values obtained from the recursive calls `fibo(n-1)` and `fibo(n-2)`.

Conclusion

In conclusion, the given function `fibo()` is an example of linear recursion. It specifically falls under head recursion, as the recursive calls are made before any other operations in the function.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Void fibo(int n) { if(n==0 || n==1) { return n; } return fibo(n-1)+fibo(n-2); } Is it linear recursion or tree recursion? Is head and tail recursion comes under linear recursion? Is this function an example of head recursion?
Question Description
Void fibo(int n) { if(n==0 || n==1) { return n; } return fibo(n-1)+fibo(n-2); } Is it linear recursion or tree recursion? Is head and tail recursion comes under linear recursion? Is this function an example of head recursion? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Void fibo(int n) { if(n==0 || n==1) { return n; } return fibo(n-1)+fibo(n-2); } Is it linear recursion or tree recursion? Is head and tail recursion comes under linear recursion? Is this function an example of head recursion? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Void fibo(int n) { if(n==0 || n==1) { return n; } return fibo(n-1)+fibo(n-2); } Is it linear recursion or tree recursion? Is head and tail recursion comes under linear recursion? Is this function an example of head recursion?.
Solutions for Void fibo(int n) { if(n==0 || n==1) { return n; } return fibo(n-1)+fibo(n-2); } Is it linear recursion or tree recursion? Is head and tail recursion comes under linear recursion? Is this function an example of head recursion? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Void fibo(int n) { if(n==0 || n==1) { return n; } return fibo(n-1)+fibo(n-2); } Is it linear recursion or tree recursion? Is head and tail recursion comes under linear recursion? Is this function an example of head recursion? defined & explained in the simplest way possible. Besides giving the explanation of Void fibo(int n) { if(n==0 || n==1) { return n; } return fibo(n-1)+fibo(n-2); } Is it linear recursion or tree recursion? Is head and tail recursion comes under linear recursion? Is this function an example of head recursion?, a detailed solution for Void fibo(int n) { if(n==0 || n==1) { return n; } return fibo(n-1)+fibo(n-2); } Is it linear recursion or tree recursion? Is head and tail recursion comes under linear recursion? Is this function an example of head recursion? has been provided alongside types of Void fibo(int n) { if(n==0 || n==1) { return n; } return fibo(n-1)+fibo(n-2); } Is it linear recursion or tree recursion? Is head and tail recursion comes under linear recursion? Is this function an example of head recursion? theory, EduRev gives you an ample number of questions to practice Void fibo(int n) { if(n==0 || n==1) { return n; } return fibo(n-1)+fibo(n-2); } Is it linear recursion or tree recursion? Is head and tail recursion comes under linear recursion? Is this function an example of head recursion? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev